package com.justnow.offer;

import java.util.*;

/**
 * @author justnow
 * Created on 2020-09-19
 * Description
 */
public class JXJR01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        s = s.replace('[', ' ');
        s = s.replace(']', ' ');
        String[] split = s.split(",");
        List<Integer> list = new ArrayList<>();
        for (String s1 : split) {
            list.add(Integer.valueOf(s1.trim()));
        }
        Map<Integer, Integer> map = new HashMap<>();
        map.put(5, 0);
        map.put(10, 0);
        map.put(20, 0);
        boolean flag = true;
        for (Integer integer : list) {
            if (integer == 5) {
                int n5 = map.get(5);
                map.put(5, n5 + 1);
            } else if (integer == 10) {
                if (map.get(5) == 0) {
                    flag = false;
                    break;
                } else {
                    int n5 = map.get(5);
                    int n10 = map.get(10);
                    map.put(5, n5 - 1);
                    map.put(10, n10 + 1);
                }
            } else {
                if (map.get(5) >= 3) {
                    int n5 = map.get(5);
                    map.put(5, n5 - 3);
                } else if (map.get(5) < 3 && map.get(10) >=1 ) {
                    int n5 = map.get(5);
                    int n10 = map.get(10);
                    map.put(5, n5 - 1);
                    map.put(10, n10 - 1);
                } else {
                    flag = false;
                    break;
                }
            }
        }

        if (flag) {
            System.out.println(true);
        } else {
            System.out.println(false);
        }
    }
}
